﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ZFB.Models;
using ZFB.Models.EntityConfig;

namespace ZFB.Repository.Setting
{
    public class SettingRepository : BaseRepository<T_Settings>, ISettingRepository
    {
        private readonly MyDbContext db;
        public SettingRepository(MyDbContext db) : base(db)
        {
            this.db = db;
        }

        public async Task<string> GetValueAsync(string name)
        {
            var data = await db.T_Settings.Where(e => !e.IsDeleted && e.Name == name).SingleOrDefaultAsync();
            if (data == null) 
                return null;
            return data.Value;
             
        }

        public async Task<int> SetValueAsync(string name, string value)
        {
            var data = await db.AddAsync(new T_Settings {Name=name,Value=value });
            if (db.SaveChanges() >= 1) return 1;
            return 0;
        }
    }
}
